<%@ include file="/include/taglibs.jsp"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>订单管理</title>
<link href="${ctx}/css/orderForm.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<%@include file="/include/head.jsp"%>
	 <!--页面中部内容-开始-->
	 <div class="common_wraper">
	 	<div class="winTopOuter">
	 		<div class="winTopInner"></div>
	 	</div>
	 	<div class="winContent">
	 		<div class="winTitle">
	 			请填写用户注册信息
	 		</div>
	 		<div class='statusImg_buyCar'></div><%--状态图片 --%>
	 		
	 		  <c:if test="${not empty buyCommodityMap}">
	 		  	<div class='buyCarArea' id='buyCarArea' >
		 		  <table class="buyCarTable"  cellpadding="0" cellspacing="0" >
			 		  <tr class="tableTr"><td width="20px" ></td><td width="50px"><input type="checkbox" name="checkbox" onclick="checkAllGood(this)"/>全选</td><td>商品名称</td><td width="70px">单价(元)</td><td width="70px">数量</td><td width="70px">运费(元)</td><td width="70px">小计(元)</td><td width="100px" align="center">操作</td></tr>
			 		    <c:forEach  var="shopNameMap" items="${buyCommodityMap}" varStatus="i">
			 		    <tr class="shopName"><td></td><td><input type="checkbox" name="checkbox" onclick="checkGoodByShopName(this,'${shopNameMap.key}')"/></td><td colspan="10">${shopNameMap.key}</td></tr>
			 		    <c:forEach var="goodInfo" items="${shopNameMap.value}">
			 		      <tr class="orderFromInfo" id="${shopNameMap.key}_${goodInfo.id}"><td ></td>
			 		      <td ><div class="orderCheckSpace"></div> <input type="checkbox" name="checkbox" value="${goodInfo.id}"/></td>
			 		      <td>${goodInfo.name}</td>
			 		      <td>${goodInfo.price}</td>
			 		      <td>${goodInfo.buycount}</td>
			 		      <td>${goodInfo.freight}</td>
			 		      <td class="amount">${goodInfo.amount}</td>
			 		      <td><a href="#" onclick="modifyInfo('${goodInfo.id}')">修改</a>&nbsp;|&nbsp;<a href="#" onclick="deleteGood('${goodInfo.id}')">删除</a></td>
			 		       </tr>
			 		    </c:forEach>
			 		    </c:forEach>
		 		  </table>
		 		</div>
		 		<div class="buyCarBtnDiv">
					<div class="btnDivInner">
						<a href="javascript:continueBuy()" class="continueBuy"></a>
						<a href="javascript:gotoOrderPage()" class="balance"></a>
					</div>
				</div>
	 		  </c:if>
	 		  <c:if test="${empty buyCommodityMap}">
	 		 	 <div class='buyCarArea' id='buyCarArea' >
	 		  		 <div class="emptyBuyArea">
	 		  		 	<div class="emptyBuyImg"></div>
	 		  		 	<div class="emptyTextArea">
	 		  		 		<strong>你的购物车还是空的，请赶快行动吧！你可以</strong>
	 		  		 		<label>如果你还没有登录，可能导致购物车为空，请<a href="#">马上登录</a>或到<a href="#">购物商店推荐</a>看看</label>
	 		  		 	</div>
	 		  		 </div>
	 		  	 </div>
	 		 </c:if>
	 	</div>

	 	<div class="winBottomOuter">
	 		<div class="winBottomInner"></div>
	 	</div>
	 </div>
	 <!--页面中部内容-结束-->
	<%@include file="/include/footer.jsp" %>
</body>
<script type="text/javascript">
	function deleteGood(id){
		if(confirm("您确定要从购物车中删除该商品吗？")){
		 window.location.href="${ctx}/buycar/buycarAction!deleteCommodity.action?commodity.id="+id;
		}
	}
	function checkAllGood(obj){
		if(obj.checked){//全选
		 $("input[name='checkbox']").attr("checked","true");
		}else{//全部取消
		 $("input[name='checkbox']").attr("checked","");	
		}
	}
	function checkGoodByShopName(obj,id){
		if($(obj).attr("checked")){//全选
			 $("tr[id^='"+id+"']").find("input[name='checkbox']").attr("checked","true");
		}else{//全部取消
			$("tr[id^='"+id+"']").find("input[name='checkbox']").attr("checked","");
		}
	}
	function modifyInfo(id){
		 $.openPopupLayer({
				name: "showGoodDiv",
				width: 1050,
				parameters: {"TimeFlags":Date.parse(new Date())},
				url: "${ctx}/buycar/buycarAction!initUpdateCommodity.action?commodity.id="+id
			});
	}
	function continueBuy(){
		var ajaxUrl="${ctx}/user/systemUserAction!ajaxUserHasLogin.action";
		$.ajax({
			type: "post",
			url: ajaxUrl,
			dataType: "text",
			data:{"timeTemp":new Date().getTime()},   
			success: function(data){
				  if(data=='02'){//未登录
					  $.openPopupLayer({
							name: "quickLogin",
							width: 1050,
							parameters: {"TimeFlags":Date.parse(new Date())},
							url: "${ctx}/user/systemUserAction!gotoQuickLogin.action"
						});
				  }else{//已登录
								  $.openPopupLayer({
									name: "showGoodDiv",
									width: 1050,
									//target: "sendblessDiv",
									parameters: {"TimeFlags":Date.parse(new Date())},
									url: "${ctx}/buycar/buycarAction!continueBuyGood.action"
					  });
				  }
				}
		});
	}
	//跳转到支付页面
	function gotoOrderPage(){
		var ids='';
		 $("input[name='checkbox']").each(function (i,obj){
			 if(obj.checked  && (obj.value!=null && obj.value!='')){
				 ids+=obj.value+",";
			 }
		 });
		 if(ids!=null && ids!=''){
			 alert(ids);
			  window.location.href="${ctx}/orderinfo/orderforminfoAction!initOrderInfo.action?goodsIds="+ids;
		 }
	}
</script>
</html>